class MovingAverage {

    double num = 0;
    int size;
    double dd = 0;
    Queue<Integer> queue; 
    /** Initialize your data structure here. */
    public MovingAverage(int size) {
        queue = new ArrayDeque<>();
        this.size = size;
    }
    
    public double next(int val) {
        num += val;
        if(queue.size() == size) {
            num -= queue.poll();
        }
        queue.offer(val);
        dd = num / queue.size();
        return dd;
    }
}

/**
 * Your MovingAverage object will be instantiated and called as such:
 * MovingAverage obj = new MovingAverage(size);
 * double param_1 = obj.next(val);
 */